<%@ Page Language="C#" MasterPageFile="~/SurveyHost.Master" AutoEventWireup="true" MaintainScrollPositionOnPostback="true"
    Codebehind="Users.aspx.cs" Inherits="SurveyHost.Web.Admin.Users"
    Title="Edit Users" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    runat="server">
    <asp:Panel ID="editControls" runat="server" Visible="False" Width="100%">
        <div class="post">
            <h1 class="title">
                Edit User
            </h1>
            <p class="byline">
                Editing user
                <%# CurrentUserName %>
            </p>
            <div class="entry">
                <div style="width: 50%; float: left;">
                    <p>
                        Email:&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                            ControlToValidate="email" ToolTip="E-mail is required." ValidationGroup="EditUser"
                            Display="dynamic">Required</asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                            runat="server" ControlToValidate="email" Display="static"
                            ValidationExpression=".*@.*\.\w{2,3}" ValidationGroup="EditUser">Please enter a valid e-mail</asp:RegularExpressionValidator><br />
                        <asp:TextBox ID="email" runat="server" Width="75%" Text="<%# CurrentUser.Email %>"></asp:TextBox></p>
                    <asp:CheckBox ID="resendCheckbox" runat="server" Text="Resend email (automatically resets the user's password)" />
                    <p>or set the password manually:<br />
                    Old password:&nbsp;<asp:TextBox runat="server" ID="oldPassword"/><br />
                    New password:&nbsp;<asp:TextBox runat="server" ID="newPassword" 
                            ontextchanged="changePasswordTextbox_TextChanged" /></p>
                </div>
                <div style="width: 50%; float: right;">
                    <p>
                        Roles:<br />
                        <asp:Repeater ID="roleRepeater" runat="server">
                            <ItemTemplate>
                                <asp:CheckBox runat="server" ID="roleChex" Text='<%# Container.DataItem.ToString()%>'
                                    Checked="<%# Roles.IsUserInRole(CurrentUser.UserName,Container.DataItem.ToString()) %>"
                                    OnCheckedChanged="RoleMembershipChanged" /><br />
                            </ItemTemplate>
                        </asp:Repeater>
                    </p>
                </div>
                <div style="clear: both; text-align: right;">
                    <asp:Button ID="applyButton" runat="server" Width="72px" Text="Apply"
                        OnClick="applyButton_Click" />&nbsp;&nbsp;
                    <asp:Button ID="cancelButton" runat="server" OnClick="cancelButton_Click"
                        Text="Cancel" Width="72px" />
                </div>
                <p>
                </p>
            </div>
        </div>
    </asp:Panel>
    <div class="post">
        <h1 class="title">
            create a new user
        </h1>
        <p class="byline">
            Enter a user name, email and select roles for the user.</p>
        <div class="entry">
            <div style="width: 50%; float: left;">
                <p>
                    User Name:&nbsp;<asp:RequiredFieldValidator ID="UserNameRequired"
                        runat="server" ControlToValidate="NewUserName" ToolTip="User Name is required."
                        ValidationGroup="CreateNewUser">User Name is required</asp:RequiredFieldValidator><br />
                    <asp:TextBox ID="NewUserName" runat="server" Width="75%" EnableViewState="False"></asp:TextBox>
                </p>
                <p>
                    E-mail:&nbsp;<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
                        ControlToValidate="NewUserEmail" ToolTip="E-mail is required."
                        ValidationGroup="CreateNewUser" Display="dynamic">Required</asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="EmailRegExp" runat="server"
                        ControlToValidate="NewUserEmail" Display="static" ValidationExpression=".*@.*\.\w{2,3}"
                        ValidationGroup="CreateNewUser">Please enter a valid e-mail</asp:RegularExpressionValidator>
                    <br />
                    <asp:TextBox ID="NewUserEmail" runat="server" Width="75%" EnableViewState="False"></asp:TextBox></p>
            </div>
            <div style="width: 50%; float: right;" title="Without a role, a user cannot do anything on the website.">
                <p>
                    Select one or more roles:<br />
                    <asp:Repeater ID="NewUserRoles" runat="server" EnableViewState="False">
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="newRoleCheckbox" Text='<%# Container.DataItem.ToString()%>' /><br />
                        </ItemTemplate>
                    </asp:Repeater>
                </p>
            </div>
            <div style="clear: both; text-align: right;">
                <asp:Literal ID="ResultMessage" runat="server" EnableViewState="False"></asp:Literal>&nbsp;
                <asp:Button ID="CreateUser" runat="server" Text="Create" ValidationGroup="CreateNewUser"
                    OnClick="CreateUser_Click" />
            </div>
        </div>
    </div>
    <div class="post">
        <h1 class="title">
            Current users
        </h1>
        <p class="byline">
            You can edit, delete, or mark users inactive</p>
        <div class="entry">
            <asp:GridView ID="dataGrid" runat="server" CellPadding="3" Width="100%"
                AutoGenerateColumns="False" GridLines="none" BorderStyle="None"
                AllowSorting="True">
                <RowStyle CssClass="gridRowStyle" BackColor="#EEEEEE" ForeColor="Black" />
                <AlternatingRowStyle CssClass="gridAlternatingRowStyle" BackColor="Gainsboro" />
                <PagerStyle CssClass="gridPagerStyle" BackColor="#999999" ForeColor="Black"
                    HorizontalAlign="Center" />
                <HeaderStyle CssClass="callOutStyle" Font-Bold="True" BackColor="#CCCCCC"
                    ForeColor="Black" HorizontalAlign="Left" />
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <SelectedRowStyle CssClass="gridSelectedRowStyle" BackColor="#008A8C"
                    Font-Bold="True" ForeColor="White" />
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton runat="server" ID="editButton" Text="Edit" CommandName="EditUser"
                                ToolTip="Click to edit this user" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "UserName")%>'
                                ForeColor="black" OnCommand="EditClick" />
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center" Width="48px" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Active">
                        <HeaderStyle HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" Width="48px" />
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="CheckBox1" OnCheckedChanged="EnabledChanged"
                                AutoPostBack="true" Checked='<%#DataBinder.Eval(Container.DataItem, "IsApproved")%>'
                                Enabled='<%#IsApprovedEnabled(DataBinder.Eval(Container.DataItem, "UserName"))%>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="User name">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="UserNameLink" ForeColor='black'
                                Text='<%#DataBinder.Eval(Container.DataItem, "UserName")%>' />
                        </ItemTemplate>
                        <HeaderTemplate>
                            User Name
                        </HeaderTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Email address">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="EmailLink" ForeColor='black' Text='<%#DataBinder.Eval(Container.DataItem, "Email")%>' />
                        </ItemTemplate>
                        <HeaderTemplate>
                            Email address
                        </HeaderTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
    </div>
</asp:Content>
